import os
import cv2
import glob
import random
import shutil

#先把图片分为训练集和验证集，将验证集移动到val文件夹，剩下的即为训练集
#根据……移动标签文件
# imgs_path = 'E:/DATASET/vocDataset/JPEGImages_copy/*.jpg'
# #glob.glob返回所有匹配的文件路径列表。
# image_list = glob.glob(imgs_path)
# #打乱
# random.shuffle(image_list)
# # print(image_list)
# #这里是划分，我设置的是0.85：0.15  可以根据自己情况划分
# num = len(image_list)
# train_list = image_list[:int(0.85*num)]
# val_list = image_list[int(0.85*num):]
# print(len(train_list),len(val_list))
# print(len(train_list)+len(val_list))
#
#
# for image_path in val_list:
#     shutil.move(image_path,r'E:\DATASET\vocDataset\kitti_5\val\images')

images_val_path = r'E:\DATASET\vocDataset\kitti_5\val\images'
images_val_list = glob.glob(images_val_path + '\\*.jpg')
# print(images_val_list)
value1,value2 = [],[]
for img_val in images_val_list:
    value1.append(img_val[-10:-4])

n=0
labels_path = r'E:\DATASET\vocDataset\yololabels'
labels_path_list = glob.glob(labels_path + '\\*.txt')
# print(labels_path_list)
for i,label_path in enumerate(labels_path_list):
    # value2.append(label_path[-10:-4])
    for flag in value1:
        if label_path[-10:-4] == flag:
            shutil.move(label_path, r'E:\DATASET\vocDataset\kitti_5\val\labels')
            n=n+1
print(n)
# print('value1',value1)
# print('value2',value2)

